//
// Created by wangliewei on 2021/8/19.
//
/*
贪心：
1、按区间左端点排序
2、维护一个区间，分三种情况更新
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int> PII;

const int N = 100010;
vector<PII> segs;

void merge(vector<PII> &segs){
    vector<PII> res;
    sort(segs.begin(), segs.end());
    int st = -2e9, ed = -2e9;//根据题中要求数据范围设置
    for (auto seg : segs) {
        if (ed < seg.first) {
            if(st != -2e9) res.push_back({st, ed});
            st = seg.first, ed = seg.second;
        }else {
            ed = max(ed, seg.second);
        }
    }
    if (st != -2e9) res.push_back({st, ed});
    segs = res;
}

int main(){

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int l,r;
        cin >> l >> r;
        segs.push_back({l,r});
    }

    merge(segs);

    cout << segs.size() << endl;


    return 0;
}
















